<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/common"/>

<script type="text/javascript">
$(function(){
	var actionName = encodeURI(encodeURI("国家代码更新"));
});
</script>

	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="edit" onclick="saveDock();" title="保存"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteDock();" title="删除"><span>删除</span></a></li>
		</ul>
	</div>

<div class="pageContent">
	<form id="bs_dock_edit" method="post" action="${path}/update.html?tableName=BS_DOCK&tableAction=update" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
		<div class="pageFormContent" layoutH="260">
			<fieldset>
				<dl>
					<dt>码头代码：</dt>
					<dd><input name="DOCK_ID" type="text" value="${dock.DOCK_ID}" class="required"/></dd>
				</dl>
				<dl>
					<dt>码头名称：</dt>
					<dd><input name="DOCK_NAME" type="text" size="30" value="${dock.DOCK_NAME}" class="required" /></dd>
				</dl>
				<dl>
					<dt>所属机构：</dt>
					<dd><input name="OWNER_ORG" type="text" size="30" value="${dock.OWNER_ORG}" /></dd>
				</dl>
				<dl>
					<dt>所属区域：</dt>
					<dd><input name="DOCK_AREA" type="text" size="30" value="${dock.DOCK_AREA}" /></dd>
				</dl>
				<dl>
					<dt>场所类型：</dt>
					<dd><input name="PLACE_TYPE" type="text" size="30" value="${dock.PLACE_TYPE}" /></dd>
				</dl>
				<dl>
					<dt>类型：</dt>
					<dd><input name="TYPE" type="text" size="30" value="${dock.TYPE}" /></dd>
				</dl>
				<dl>
					<dt>性质：</dt>
					<dd><input name="NATURE" type="text" size="30" value="${dock.NATURE}" /></dd>
				</dl>
				<dl>
					<dt>性质：</dt>
					<dd><input name="JS_CODE" type="text" size="30" value="${dock.JS_CODE}" /></dd>
				</dl>
				<dl>
					<dt>使用状态：</dt>
					<dd>
					<select class="combox" name="STATE" >
						<option value="1" <c:if test="${dock.STATE==1}">selected</c:if> >启用</option>
						<option value="0" <c:if test="${dock.STATE==0}">selected</c:if> >禁用</option>
					</select>
					<input name="CREATE_USER" type="hidden" value="${dock.CREATE_USER}" />
					</dd>
				</dl>
			</fieldset>
		</div>
		
		<div class="pageFormContent" layoutH="160">
		<div class="tabs">
		<div class="tabsHeader">
			<div class="tabsHeaderContent">
				<ul>
					<li class="selected"><a href="javascript:void(0)"><span>操作单元列表</span></a></li>
				</ul>
			</div>
		</div>
		<div class="tabsContent" style="height: 160px;">
			<div>
				<div class="panelBar">
					<ul class="toolBar">
						<li><a class="add" onclick="addBerth();" title="添加泊位"><span>添加泊位</span></a><br /><br /></li>
						<li class="line">line</li>
						<li><a class="edit" onclick="editBerth();" title="编辑泊位"><span>编辑泊位</span></a></li>
					</ul>
				</div>

				<table class="table" width="100%" >
					<thead>
						<tr>
							<th width="80">泊位代码</th>
							<th width="160">泊位名称</th>
							<th width="160">省电子口岸代码</th>
							<th width="30">使用状态</th>
						</tr>

					</thead>
						<tbody id="base_define_action_set_list_tbody">
						<c:if test="${! empty berth}">
						<c:forEach var="data" items="${berth}">
						<tr target="params" rel="${data.BERTH_ID}" class="bs_dock_berth_list_tr">
							<td>${data.BERTH_ID}</td>
							<td>${data.BERTH_NAME}</td>
							<td>${data.JS_CODE}</td>
							<td>
							<c:choose>
							<c:when test="${data.STATE==1}">启用</c:when>
							<c:otherwise>禁用</c:otherwise>
							</c:choose>
							</td>
						</tr>
						</c:forEach>
						</c:if>
					</tbody>
				</table>

			</div>

		</div>
		</div>
	</div>
		
	</form>
</div>

<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			// navTab.reload("${path}/list.html");//刷新
			$(bs_dock_list).submit();
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function saveDock() {
	$("#bs_dock_edit").submit();
}

function deleteDock() {
	var rel = '';
	$('.bs_dock_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var url = "${path}/update.html?tableName=BS_DOCK&tableAction=delete&DOCK_ID=" + rel;
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/search.html?tableName=BS_DOCK&tableAction=list&jsp=ship/base/dock_list";
						navTab.reload(url);
						setTimeout(function(){$.pdialog.closeCurrent();}, 100); // 关闭此编辑页签
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

function addBerth(){
	if("${dock.DOCK_ID}" == "") {
		alertMsg.warn('请先保存码头数据后再添加泊位信息！');
		return;
	}
	var url = "${path}/view.html?jsp=ship/base/dock_berth_edit&js_back_function=addBerthBack&DOCK_ID=${dock.DOCK_ID}";
	$.pdialog.open(url, "bs_dock_berth_add", "添加泊位操作",{width:800,height:480,mask:true,maxable:false,resizable:false});
}

function editBerth(){
	var rel = '';
	$('.bs_dock_berth_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条泊位数据！');
	}else{
		var url = "${path}/search.html?tableName=BS_BERTH&tableAction=load&jsp=ship/base/dock_berth_edit&js_back_function=addBerthBack&DOCK_ID=${dock.DOCK_ID}&BERTH_ID="+rel;
		$.pdialog.open(url, "bs_dock_berth_add", "编辑泊位操作",{width:800,height:480,mask:true,maxable:false,resizable:false});
	}
}

/**
 * 回调函数
 * 当泊位数据变更后，此方法重新从数据库中获取泊位信息
 */
function addBerthBack(){
	var params = $("#bs_dock_edit").serialize();
	params = decodeURIComponent(params,true);
	// 将值部分二次转码，以防出现中文乱码的问题
	params = convertUTF8(params);
	var url = "${path}/action.html?name=bs_dock_load&jsp=ship/base/dock_edit&"+ params;
	// 关闭子参照窗体
	$.pdialog.close("bs_dock_berth_add");
	// 重新打开本窗体
	$.pdialog.open(url, "ship_base_dock_edit", "修改码头信息",{width:800,height:480,mask:true,maxable:false,resizable:false});
}

/**
 * 将URL请求参数中值的部分二次转码，以防出现中文乱码
 * 例：actionType=&name=q&sort=q&description=q&dwz_rowNum=1&items.key%5B0%5D=q
 */
function convertUTF8(args){
	var params = "";
	var arr = args.split("&");
	for(var s in arr){
		var array = arr[s].split("=");
		if(array[1] != ""){
			params = params + '&' + array[0] + '=' + encodeURI(encodeURI(array[1]));
		}
	}
	return params.substr(1);
}

</script>